Use case: Starting the GFXTIM with absolute frame timer ¶
This use case shows how to start the absolute frame counter and handle frame compare and overflow events.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
GFXTIM_HandleTypeDef hgfxtim;
hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_AFC_COMPARE1_CB_ID,
USER_GFXTIM_ABSTIM_FrmCmpCallback);
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_AFC_OVERFLOW_CB_ID,
USER_GFXTIM_ABSTIM_FrmCntOverFlowCallback);
/* Configure the GFXTIM clock generator */
GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
.LineClockSrc = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;
.FCCHwReloadSrc = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue = 1;
.FCCClockSrc = GFXTIM_FCC_CLK_SRC_HSYNC_RISING;
.FrameClockSrc = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
&pClockGenConfig);
/* Configure the GFXTIM clock generator */
GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
.FrameCompare1Value = 0xFFFFA;
.LineCompare1Value = 0;
.LineCompare2Value = 0;
.FrameCounterValue = 0xFFFF0;
.LineCounterValue = 0;
/* optional: if interrupt is enabled */
.FrameOverflowInterrupt = ENABLE;
.FrameCompare1Interrupt = ENABLE;
.LineOverflowInterrupt = DISABLE;
.LineCompare1Interrupt = DISABLE;
.LineCompare2Interrupt = DISABLE;
};
HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
&pAbsoluteTimerConfig);
/* Start the absolute line counter */
HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_AbsoluteTimer_AFCC1Callback(&hgfxtim);
USER_GFXTIM_AbsoluteTimer_ALFOFCallback(&hgfxtim);
/* Disable the absolute frame counter */
HAL_GFXTIM_AbsoluteTimer_Stop(&hgfxtim);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
hal_gfxtim_handle_t hgfxtim;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_ABSTIM_RegisterFCmpCallback(&hgfxtim,
USER_GFXTIM_ABSTIM_FrameCmpCallback);
HAL_GFXTIM_ABSTIM_RegisterFCntOverFlowCallback(&hgfxtim,
USER_GFXTIM_ABSTIM_FrameCntOverFlowCallback);
/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_HSYNC_RISING;
.clock_src = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};
HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
&p_frame_config);
/* Set the absolute frame compare value */
HAL_GFXTIM_ABSTIM_SetFrameCompareValue(&hgfxtim, 0xFFFFA);
/* Set the absolute frame counter */
HAL_GFXTIM_ABSTIM_SetFrameCounter(&hgfxtim, 0xFFFF0);
/* Start the absolute frame counter (interrupt disabled)*/
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
HAL_GFXTIM_ABSTIM_FRAME_COUNTER,
HAL_GFXTIM_NONE_IT);
/* optional: if interrupt is enabled */
/* Start the absolute frame counter in interrupt mode*/
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
HAL_GFXTIM_ABSTIM_FRAME_COUNTER,
HAL_GFXTIM_ABSTIM_LINE_ALL_IT);
/* IRQHandler function */
HAL_GFXTIM_ABSTIM_FrameIRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_ABSTIM_FCmpCallback(&hgfxtim):
USER_GFXTIM_ABSTIM_FCntOverFlowCallback(&hgfxtim);
/* optional */
/* Pause the absolute frame counter */
HAL_GFXTIM_ABSTIM_Pause(&hgfxtim,
HAL_GFXTIM_ABSTIM_FRAME_COUNTER);
/* Check that the absolute frame counter is paused */
HAL_GFXTIM_ABSTIM_Resume(&hgfxtim,
HAL_GFXTIM_ABSTIM_FRAME_COUNTER);
/* Disable the absolute frame counter */
HAL_GFXTIM_ABSTIM_Stop(&hgfxtim,
HAL_GFXTIM_ABSTIM_FRAME_COUNTER);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
Key changes ¶
HAL2 replaces the absolute timer configuration structure with unitary APIs for frame counter and compare configuration.
HAL2 provides a dedicated frame clock generator configuration API.

